package com.shqcjd.preinstallmobile.ui.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.shqcjd.preinstallmobile.R;
import com.shqcjd.preinstallmobile.model.pojo.IndexBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 头条新闻
 * Created by sy on 2019/3/15.
 */

public class HeadlinesAdapter extends BaseQuickAdapter<IndexBean.NewsBean,HeadlinesAdapter.ViewHolder> {

    public HeadlinesAdapter(@Nullable List<IndexBean.NewsBean> data) {
        super(R.layout.item_headlines, data);
    }

    @Override
    protected void convert(ViewHolder helper, IndexBean.NewsBean item) {
        helper.tv_title.setText(item.title);

        RequestOptions options = new RequestOptions()
                .placeholder(R.mipmap.ic_default_big)	//加载成功之前占位图
                .error(R.mipmap.ic_error_big)	//加载错误之后的错误图
                .centerCrop();//指定图片的缩放类型为centerCrop （等比例缩放图片，直到图片的宽高都

        Glide.with(mContext)
                .load(item.img)
                .apply(options)
                .into(helper.iv_new_img);

        helper.tv_title.setText(item.title);
    }

    class ViewHolder extends BaseViewHolder {
        @BindView(R.id.iv_new_img)
        ImageView iv_new_img;
        @BindView(R.id.tv_title)
        TextView tv_title;
        public ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

}
